package com.pri.chat.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.entity.DTBean;
import com.netease.nim.uikit.net.entity.SystemMsgBean;
import com.pri.chat.R;
import com.pri.chat.activity.OtherPeopleMsgActivity;
import com.vondear.rxtool.RxActivityTool;

import java.util.List;

import androidx.annotation.Nullable;

/**
 * 描述：添加类的描述
 *
 * @author 金源
 * @time 2020/5/12
 */
public class ZanMsgAdapter extends BaseQuickAdapter<SystemMsgBean, BaseViewHolder> {
    private int actual_width;
    public ZanMsgAdapter(int layoutResId, @Nullable List<SystemMsgBean> data) {
        super(layoutResId, data);
    }
    /**
     * 加载视频帧图
     *
     * @param imageView 展示图片view
     * @param url       视频链接
     * @param context   上下文
     */
    public static void loadCover(ImageView imageView, String url, Context context) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.img_default)//图片加载出来前，显示的图片
                .fallback( R.mipmap.img_default) //url为空的时候,显示的图片
                .error(R.mipmap.img_default)
                .transform(new CenterCrop(), new RoundedCorners(10));//图片加载失败后，显示的图片
        Glide.with(context).load(url).apply(options).into(imageView);

    }
    @Override
    protected void convert(BaseViewHolder holder, SystemMsgBean item) {
        ImageView headPic = holder.getView(R.id.headPic);
        Glide.with(mContext)
                .asDrawable()
                .load(item.getHeadPic())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(headPic);
        ImageView vedio_img = holder.getView(R.id.vedio_img);
        holder.setText(R.id.msg_membername,item.getNcName());
        holder.setText(R.id.msg_content, item.getContent());
        holder.setText(R.id.msg_time, item.getAddDate());
        ImageView vedio_tishi = holder.getView(R.id.vedio_tishi);
        String url = "";
        if(item.getType().equals("40") || item.getType().equals("70")){
            //动态
            url = item.getPicList().split(",")[0];
            vedio_tishi.setVisibility(View.GONE);
        }else{
            url = item.getVideoPath() + "?vframe/jpg/offset/1";
            vedio_tishi.setVisibility(View.VISIBLE);
        }
        loadCover(vedio_img, url,mContext);

        headPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putString("id",item.getHandMemberId());
                RxActivityTool.skipActivity(mContext, OtherPeopleMsgActivity.class,bundle);
            }
        });
    }
}
